<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of report
 *
 * @author Константин Охотник
 */

class SomeProduct extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->issetSession('SomeProduct');
        $this->load->model('SomeProductModel');
        $this->load->model('SomeOrderModel');
    }
    
    public function index($id=false,$printproduct=false)
    {
        if($id==false)
        {
            redirect('/storage/', 'refresh');
        }
        $product_data =   $this->SomeProductModel->getProductData($id);
        $categories =   $this->SomeOrderModel->getCategory();
        $fabricator =   $this->SomeOrderModel->getFabricator();
        $this->crud
        ->assign('product_data', $product_data)
        ->assign('categories', $categories)
        ->assign('fabricator', $fabricator);
        if($printproduct == false)
        {
            $this->crud->display('someproduct.tpl');
        }
        else
        {
            $this->crud->display('module/printproduct.tpl');
        }
    }
    
    public function insertdata()
    {
        $data = $this->input->post();
        //$data['date'] = date('Y-m-d'); Создать логирование на изменение

        if($data['fabricator']!='')
        {
           $this->SomeOrderModel->add_db('tb_fabricator', array('name'=>$data['fabricator']));
           $id_fabricator = $this->SomeOrderModel->get_one('tb_fabricator', 'name', $data['fabricator']);
           $data['id_fabricator'] = $id_fabricator[0]['id'];
        }
        unset($data['fabricator']);
        $id = $data['id'];
        unset($data['id']);
        die($this->SomeOrderModel->update_post('tb_product', 'id', $id, $data));
    }
}